<template>
	<view class="exchange">
		<view class="exchangekai">
			<view class="exchangekai-fen">{{user.score}}</view>
			<view class="exchangekai-tab">
				<view class="exchangekai-tab-f"  @click="urlClick('/pages/exchange/record')">
					<image src="../../static/mingxi.png"></image>
					<view>积分明细</view>
				</view>
				
				<view class="exchangekai-tab-f" @click="urlClick('/pages/exchange/convert')">
					<image src="../../static/duijilu.png"></image>
					<view>兑换记录</view>
				</view>
				
			</view>
		</view>
		
		<view class="exchangelist">
			<view class="exchangelist-title">积分好礼</view>
			<view class="exchangelist-flex">
				<view class="exchangelist-flex-v" v-for="(item,index) in list">
					<view class="exchangelist-flex-v-1">
						<image :src="item.cover_img_text"></image>
					</view>
					<view>{{item.name}}</view>
					<view class="exchangelist-flex-v-2">
						<view class="exchangelist-flex-v-2-1">
							
							<view class="exchangelist-flex-v-2-1-flex">
								<text>{{item.integral}}</text>
								<image src="../../static/jindou.png"></image>
							</view>
						</view>
						<view class="exchangelist-flex-v-2-2" @click="duihuanClick(item)">兑换</view>
					</view>
					
				</view>
				
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: [],
				list : []
			}
		},
		onLoad() {
			this.getall();
		},
		methods: {
			urlClick(e){
				uni.navigateTo({
					url:e
				});
			},
			duihuanClick(e){
				let that = this;
				if(e.integral > that.user.score){
					uni.showToast({
						title: '积分不足',
						icon: 'none'
					});return;
				}
				if(e.number  ==0) {
					uni.showToast({
						title: '库存不足',
						icon: 'none'
					});return;
				}
				that.$api.setconversion({'exchange_id':e.id}).then(res=>{
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					if(res.code == 1){
						that.getall();
					}
					console.log(res);
				})
				
				console.log(e);
			},
			getall(){
				let that = this;
				that.$api.userinfo({}).then(res=>{
					if(res.code == 1){
						that.user = res.data.user;
					}
					console.log(res);
				})
				that.$api.getexchangeall({}).then(res=>{
					if(res.code == 1){
						that.list = res.data.list;
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.exchange {
		color: #333;
		width: 750rpx;
		height: 100%;
		background-image:linear-gradient(#ffcf41,#fcf5e0,#f7f5f0,#f7f5f0);
		.exchangekai {
			background-image: url('../../static/jifen.png');
			width: 690rpx;
			margin: auto;
			position: relative;
			top: 60rpx;
			background-size: 100% 100%;
			height: 340rpx;
			.exchangekai-fen {
				font-size: 50rpx;
				padding-left: 60rpx;
				padding-top: 46rpx;
			}
			.exchangekai-tab {
				display: flex;
				margin-top: 60rpx;
				justify-content: center;
				.exchangekai-tab-f {
					width: 140rpx;
					text-align: center;
					flex: 1;
					
					image {
						width: 80rpx;
						height: 80rpx;
						margin-top: 20rpx;
					}
					view {
						color: #333;
						font-size: 32rpx;
					}
				}
			}
		}
		.exchangelist {
			width: 690rpx;
			min-height: 860rpx;
			background-color: #fff;
			margin: auto;
			margin-top: 100rpx;
			border-radius: 20rpx;
			.exchangelist-title {
				text-align: center;
				font-size: 38rpx;
				padding-top: 30rpx;
				font-weight: bold;
				letter-spacing: 4rpx;
			}
			.exchangelist-flex {
				display: flex;
				flex-wrap: wrap;
				padding: 30rpx;
				margin-top: 20rpx;
				.exchangelist-flex-v {
					width: 280rpx;
					margin-left: 24rpx;
					margin-bottom: 50rpx;
					.exchangelist-flex-v-1 {
						border-radius: 20rpx;
						height: 280rpx;
						background-color: #f8f8f8;
						display: flex;
						align-items: center;
						margin-bottom: 20rpx;
						image {
							width: 160rpx;
							height: 160rpx;
							display: block;
							margin: auto;
						}
					}
					.exchangelist-flex-v-2 {
						display: flex;
						.exchangelist-flex-v-2-1 {
							width: 180rpx;
						}
						.exchangelist-flex-v-2-1-flex {
							color: #ffcf41;
							image {
								width: 40rpx;
								height: 40rpx;
								position: relative;
								top: 6rpx;
							}
						}
						.exchangelist-flex-v-2-2 {
							width: 90rpx;
							height: 50rpx;
							line-height: 50rpx;
							text-align: center;
							color: #fff;
							border-radius: 10rpx;
							background-color: #ffcf41;
							font-size: 32rpx;
						}
					}
				}
			}
		}
	}
</style>
